package com.konghao.test.junit.util;

import java.sql.*;

/**
 * DbUtil--JunitTest
 *
 * @author: Jovi
 * @createTime: 2017-09-28 16:57
 **/
public class DbUtil {

    public static Connection getConnection() throws SQLException {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        Connection conn = DriverManager.getConnection
                ("jdbc:mysql://localhost:3306/test_junit", "root", "123456");
        return conn;
    }

    public static void close(Connection connection) throws SQLException {
        if (connection != null) {
            connection.close();
        }
    }

    public static void close(PreparedStatement pre) throws SQLException {
        if (pre != null) {
            pre.close();
        }
    }

    public static void close(ResultSet rs) throws SQLException {
        if (rs != null) {
            rs.close();
        }
    }
}
